<extend name="../Common/comm-block"/>
<block name="body">
    fdsfskls
</block>
<block name="script">
    <script type="text/javascript">
        // 链表基本结构 每个节点只能存储一个值
        function ListNode(val) {
            this.val = val;
            this.next = null;
        }

        /**
         * @param {ListNode} l1
         * @param {ListNode} l2
         * @return {ListNode}
         */
        var addTwoNumbers = function (l1, l2) {
            // 逢十进一算
            var l = l1, r = l2;
            var res = new ListNode(null);
            var curr = res; // 当前指针
            var carry = 0; // 哑节点 即 进几
            while (l || r || carry) {
                var lnum = 0, rnum=0;
                if(l) lnum = l.val;
                if(r) rnum = r.val;
                var sum = carry + parseInt(lnum) + parseInt(rnum);
                carry = parseInt(sum / 10);// 进一取整数部分
                curr.next = new ListNode(sum % 10); // 取余
                curr = curr.next; // 指针向下
                if(l) l=l.next;
                if(r) r=r.next;
            }
            return res.next;
        };

        function createNode(list) {
            var res = new ListNode(list[0]);
            var curr = res;
            for (var k = 1; (list.length - 1) >= k; k++) {
                curr.next = new ListNode(list[k]);
                curr = curr.next;
            }
            return res;
        }

        var l1 = createNode([5]);
        var l2 = createNode([5]);
        console.log(addTwoNumbers(l1, l2));
    </script>
</block>